var e = require;
var t = module;
var n = exports;
Object.defineProperty(n, "__esModule", {
    value: !0
});
var o = e("ViewBase"),
i = e("SkinItem"),
a = e("DataMgr"),
r = e("VideoHint"),
s = cc._decorator,
c = s.ccclass,
l = s.property,
d = function(e) {
    __extends(t, e);
    function t() {
        var t = null !== e && e.apply(this, arguments) || this;
        t.skinItems = [];
        t.priceLabel = null;
        t.coinBtnPriceLabel = null;
        t.adBtn = null;
        t.getCoinBtn = null;
        t.skinFrame = null;
        t.itemParent = null;
        t.skinPriceArr = [500, 550, 600, 650, 700, 750, 800, 1e3];
        t.curPrice = 9999;
        t.unlockIndex = 0;
        return t
    }
    n = t;
    t.prototype.enter = function(t) {
        e.prototype.enter.call(this, t);
        n.Instance = this;
        a.GlobalEvent.on("SkinChange", this.freshSkin, this);
        this.skinItems = this.itemParent.getComponentsInChildren(i.default);
        a.default.Instance.curSkinNum > 8 && (a.default.Instance.curSkinNum = 0);
        this.freshSkin();
        if (a.default.Instance.coinNum < this.curPrice) {
            this.getCoinBtn.active = !0;
            this.coinBtnPriceLabel.string = "+" + this.curPrice.toString()
        } else this.getCoinBtn.active = !1
    };
    t.prototype.freshSkin = function() {
        this.skinFrame.setPosition(this.itemParent.position.add(this.skinItems[a.default.Instance.curSkinNum].node.position));
        var e = 0;
        this.unlockIndex = -1;
        for (var t = 0; t < n.unlockIndexs.length; t++) a.default.Instance.hasSkin(n.unlockIndexs[t]) ? e++:-1 == this.unlockIndex && (this.unlockIndex = n.unlockIndexs[t]);
        if (e < 8) {
            this.adBtn.enabled = !0;
            this.curPrice = this.skinPriceArr[e];
            this.priceLabel.string = this.curPrice.toString()
        } else this.adBtn.enabled = !1;
        for (t = 0; t < this.skinItems.length; t++) this.skinItems[t].setState(t, a.default.Instance.hasSkin(t));
        if (a.default.Instance.coinNum < this.curPrice) {
            this.getCoinBtn.active = !0;
            this.coinBtnPriceLabel.string = "+" + this.curPrice.toString()
        } else this.getCoinBtn.active = !1
    };
    t.prototype.skinClick = function(e) {
        console.log("skinClick", e);
        if (a.default.Instance.hasSkin(e)) a.default.Instance.curSkinNum = e;
        else {
            console.log("皮肤未解锁", e);
            SDK.ToastMgr.Inst.showToast("皮肤未解锁")
        }
    };
    t.prototype.randomPos = function() {
        var e = this;
        this.adBtn.enabled = !1;
        var t = [];
        n.unlockIndexs.forEach(function(e) {
            a.default.Instance.hasSkin(e) || t.push(e)
        });
        t.sort(function() {
            return.5 - Math.random()
        });
        console.log(t);
        for (var o = function(n) {
            setTimeout(function() {
                e.skinFrame.setPosition(e.itemParent.position.add(e.skinItems[t[n]].node.position))
            },
            200 + 100 * n + 200 * n)
        },
        i = 0; i < t.length; i++) o(i);
        setTimeout(function() {
            e.skinFrame.setPosition(e.itemParent.position.add(e.skinItems[a.default.Instance.curSkinNum].node.position));
            a.default.Instance.setSkin(e.unlockIndex, !0);
            a.default.Instance.curSkinNum = e.unlockIndex;
            SDK.ToastMgr.Inst.showToast("皮肤购买成功")
        },
        600 + 100 * t.length + 200 * t.length)
    };
    t.prototype.buyBtnClick = function() {
        if (a.default.Instance.coinNum >= this.curPrice) {
            a.default.Instance.coinNum -= this.curPrice;
            this.randomPos()
        } else SDK.ToastMgr.Inst.showToast("金币不足")
    };
    t.prototype.coinAdBtnClick = function() {
        var e = this,
        t = "ShopGetCoin_Ad";
        SDK.Mgr.Inst.event(t + "Click");
        var n = function(o) {
            if (o == SDK.Define.AdsCode.finish) {
                SDK.Mgr.Inst.event(t + "Success");
                a.default.Instance.coinNum += e.curPrice;
                a.default.Instance.videoAdTimes++;
                e.getCoinBtn.active = !1
            } else if (o == SDK.Define.AdsCode.cancel) {
                SDK.Mgr.Inst.event(t + "Cancel");
                r.default.Instance.openPanel(n)
            } else {
                SDK.ToastMgr.Inst.showToast("暂无广告，请稍后再试");
                SDK.Mgr.Inst.event(t + "NoAd")
            }
        };
        SDK.Mgr.Inst.showVideo(n)
    };
    t.prototype.closePanel = function() {
        e.prototype.exit.call(this);
        a.GlobalEvent.off("SkinChange", this.freshSkin, this)
    };
    var n;
    t.Instance = null;
    t.unlockIndexs = [2, 3, 4, 1, 5, 7, 6, 8];
    __decorate([l(cc.Label)], t.prototype, "priceLabel", void 0);
    __decorate([l(cc.Label)], t.prototype, "coinBtnPriceLabel", void 0);
    __decorate([l(cc.Button)], t.prototype, "adBtn", void 0);
    __decorate([l(cc.Node)], t.prototype, "getCoinBtn", void 0);
    __decorate([l(cc.Node)], t.prototype, "skinFrame", void 0);
    __decorate([l(cc.Node)], t.prototype, "itemParent", void 0);
    return n = __decorate([c], t)
} (o.default);
n.default = d